#!/bin/bash

ARCH=$1
GCC="$ARCH"-gcc

CPU_FAMILY=`echo $ARCH | awk -F- '{print $1}'`
SYSTEM=`echo $ | awk -F- '{print $2}'`

DIR=`dirname $0`
TMPL=$DIR/cross.tmpl

CROSS=cross-$ARCH.txt
BUILD=build-$ARCH

sed \
    -e "s/@ARCH@/$ARCH/" \
    -e "s/@SYSTEM@/$SYSTEM/" \
    -e "s/@CPU@/$CPU/" \
    -e "s/@C_ARGS@/'-DTINY_STDIO', $C_ARGS/" \
    -e "s/@ENDIAN@/$ENDIAN/" \
    $TMPL > $CROSS

meson $DIR $DIR/$BUILD -Dincludedir=lib/newlib-nano/$ARCH/include -Dlibdir=lib/newlib-nano/$ARCH/lib --cross-file $CROSS
